package com.itc.dispatch.common;
import org.springframework.beans.BeanUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;


public class BeanFlightCopy {

    public static void copyPropertiesIgnoreNull(Object source, Object target) {
        PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(source.getClass());
        for (PropertyDescriptor pd : propertyDescriptors) {
            String propertyName = pd.getName();
            if ("class".equals(propertyName)) {
                continue;
            }
            try {
                Method getter = pd.getReadMethod();
                Method setter = pd.getWriteMethod();
                if (getter != null && setter != null) {
                    Object value = getter.invoke(source);
                    if (value != null) {
                        setter.invoke(target, value);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }


}
